package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.mapper.UserMapper;
import org.example.pojo.User;
import org.example.pojo.UserProfile;
import org.example.service.UserProfileService;
import org.example.mapper.UserProfileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【user_profile(用户扩展信息表)】的数据库操作Service实现
* @createDate 2025-04-21 09:38:38
*/
@Service
public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserProfile>
    implements UserProfileService{
    @Autowired
    private UserProfileMapper dao;
    @Autowired
    private UserMapper dao2;

    @Override
    public UserProfile findall(int id) {
        QueryWrapper<UserProfile> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid",id);
        UserProfile userProfile1 = dao.selectOne(queryWrapper);
        User user = dao2.selectById(userProfile1.getUid());
        userProfile1.setPhone(user.getPhone());
        userProfile1.setEmail(user.getEmail());
        userProfile1.setTou(user.getAvatarUrl());
        System.err.println(userProfile1);
        return userProfile1;
    }

    @Override
    public int add(UserProfile up) {
        System.err.println(up);
        int insert = dao.insert(up);
        System.err.println(up);
        return insert;
    }

    @Override
    public int upd(UserProfile userProfile) {
        int i = dao.updateById(userProfile);

        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("id",userProfile.getUid());
        User user = dao2.selectOne(userQueryWrapper);
        user.setId(userProfile.getUid());
        user.setEmail(userProfile.getEmail());
        user.setPhone(userProfile.getPhone());
        user.setAvatarUrl(userProfile.getTou());
        dao2.updateById(user);

        System.err.println(userProfile);


        System.err.println("修改成功");
        return i;
    }
}




